$import('View');
$import('DomUtil');
$import('Tag');
var ListView = $createClass('ListView',function(param){
	this.View(param);
	this.lineFun = param.lineFun;
	this.lineSplitFun = param.lineSplitFun;
	this.domId = param.domId;
	
},'View');
/**
 * 根据pojo返回对应的line的dom
 */
ListView.prototype.getLineDom = function(pojo){
	
	var dom = document.getElementById(this.buildId(pojo));
	return dom;
}

ListView.prototype.refresh = function(){
	var model = this.model;
	if(model){
		this.refreshList();
		this.setCurrent(model.getCur());
	}
}
ListView.prototype.refreshList = function(){
	var self = this;
	DomUtil.addDomByArray(this.domId,this.getDataList(),function(pojo){
		var ret = self.lineFun(pojo);
		if(ret){
			ret.id(self.buildId(pojo));
		}
		return ret;
	},function(pojo){
		if(self.lineSplitFun)
			return self.lineSplitFun(pojo);
	});
}

ListView.prototype.buildId = function(pojo,text){
	var ret = this.name+ViewUtil.splitChar+this.model.buildId(pojo);
	if(text)
		ret =ret + ViewUtil.splitChar+text;
	return ret;
}

/**
 * 从model返回list
 */
ListView.prototype.getDataList = function(){
	if(this.model)
		return this.model.list();
	return null;
}


